package ru.ifmo.croak.api;

import java.io.Serializable;

/**
 * {@code QueryRequest} contains filtering parameters for a query.
 *
 * @author Roman Elizarov
 */
public class QueryRequest implements Cloneable, Serializable {
    private String author;
    private String text;
    private int limit;

    /**
     * Returns filter for an author of a message.
     * Only messages from this author match a query.
     * If query author is null, then messages from any author are acceptable.
     */
    public String getAuthor() {
        return author;
    }

    /**
     * Sets filter for an author of a message.
     */
    public void setAuthor(String author) {
        this.author = author;
    }

    /**
     * Returns filter for a text of a message.
     * Only messages containing this text match a query.
     * If query text is null, then messages with any text are acceptable.
     */
    public String getText() {
        return text;
    }

    /**
     * Sets filter for a text of a message.
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Returns a limit of the number of most recent messages that match a query.
     */
    public int getLimit() {
        return limit;
    }

    /**
     * Sets a limit of the number of most recent messages that match a query.
     */
    public void setLimit(int limit) {
        this.limit = limit;
    }

    /**
     * Creates a copy of this query request.
     */
    @Override
    public QueryRequest clone() {
        try {
            return (QueryRequest) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e); // this cannot happen
        }
    }

    /**
     * Returns string representation of this query request.
     */
    @Override
    public String toString() {
        return "QueryRequest{" +
                "author='" + author + '\'' +
                ", text='" + text + '\'' +
                ", limit=" + limit +
                '}';
    }
}
